export const CHNumber: { [num: number]: string } = { 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 7: '七', 8: '八', 9: '九', 0: '零' };

export function getCHNumber(idx: number) {
  let ch = '';
  while (idx != 0) {
    const a = idx % 10;
    ch = CHNumber[a] + ch;
    idx = Math.floor(idx / 10);
  }
  return ch;
}
/**
 * 获得字符串实际长度，中文2，英文1
 * @param str
 * @returns 要获得长度的字符串
 */
export const getStrLength = (str: string) => {
  let realLength = 0,
    len = str.length,
    charCode = -1;
  for (let i = 0; i < len; i++) {
    charCode = str.charCodeAt(i);
    if (charCode >= 0 && charCode <= 128) realLength += 1;
    else realLength += 2;
  }
  return realLength;
};
